package com.xhwl.logistics.strategy.context;

import com.xhwl.common.enums.vehicle.SyncTypeEnum;
import com.xhwl.logistics.strategy.BasicInfoSyncStrategy;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * @description: 基础信息同步策略
 * @author: lu.Aaron
 * @create: 2021-06-30 09:07
 **/
//@Component
public class BasicInfoSyncStrategyContext {
    @Autowired
    private List<BasicInfoSyncStrategy> list;
    private Map<Integer,BasicInfoSyncStrategy> basicInfoSyncStrategyMap=new ConcurrentHashMap<>();
    @PostConstruct
    public void init(){
        basicInfoSyncStrategyMap=list.stream().collect(Collectors.toMap(BasicInfoSyncStrategy::getSyncType,b->b));
    }

    /**
     * 根据type在容器中获取对应的实现类
     * @param syncTypeEnum
     * @return
     */
    public BasicInfoSyncStrategy getBasicInfoSyncService(SyncTypeEnum syncTypeEnum){
        return basicInfoSyncStrategyMap.get(syncTypeEnum.type);
    }
}

